# -*- coding=UTF-8 -*-



"""
爬取
url = 'http://tieba.baidu.com/p/2460150866'
前三页所有的图片
"""



import requests
from urllib.request import urlretrieve
import re
import os


#url = "http://tieba.baidu.com/p/2460150866"
#sai_1 = {'Upgrade-Insecure-Requests':'1',
#    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'}


def ssk_1(url):
    try:
        sai_2 = requests.get((url))
        return sai_2.text
    except Exception as e:
        print(e)

def ssk_2(aot):
    try:
        zheng_1 = r'src="(.+?\.jpg|png|gif)" pic_ext'
        kao = re.compile(zheng_1)
        kkk_1 = re.findall(kao,aot)
        nai = 1
        for op in kkk_1:
            os.mknod("maig")
            #open("maig" 'rb+')

            urlretrieve(op,'./maig/' + '%s.jpg' % nai)
            nai += 1

    except Exception as t:
        print(t)




if __name__=="__main__":
     for ss in 'https://tieba.baidu.com/p/2460150866?pn={}'.format(3):
         hai = ssk_1(ss)
         ssk_2(hai)
         print('处理完毕')


